<template>
	<view class="indexs" style="height: 100%">
		<view class="header header_wi" :style="'padding-top: ' + navH + 'px;'">
			<view class="header_height" :style="'height:' + gaodu + 'px;line-height:' + gaodu + 'px;top:' + gaodutops + 'px;'">
				<view class="index_h_cont3">
					<view class="index_wenben_img" @tap="jumpzuo"><image :src="imgUrl + '/dzx_img33.png'" mode="widthFix"></image></view>
					<view class="index_wenben">{{ $t('page_my_fenxiaoewm.My_share_poster') }}</view>
				</view>
			</view>
			<view class="coloe_title">s</view>
		</view>
		<view class="index_center" :style="'padding-top:' + (navH + 50) + 'px;'">
			<view class="my_fenxiaoewm_center">
				<view class="loading-tips" v-if="!shareImage">
					<view class="loading-text-h">{{ $t('page_my_fenxiaoewm.Share_poster_generation') }}</view>
				</view>
				<view @click="longpress" class="my_fenxiaoewm_item1" v-if="shareImage"><image mode="widthFix" :src="shareImage"></image></view>
				<button class="saveposter" @tap="longpress">{{ $t('page_my_fenxiaoewm.save') }}</button>
			</view>
		</view>
	</view>
</template>

<script>
// pages/shouye/shouye_zkc/shouye_zkc.js
const app = getApp();

let request = require('../../../utils/require');

export default {
	data() {
		return {
			navH: app.globalData.navHeight,
			gaodu: app.globalData.height,
			gaodutops: app.globalData.top,
			imgUrl: app.globalData.imgUrl,
			shareImage: '',
			urlimg: app.globalData.urlimg,
			code: '',
			user: 0
		};
	},
	/**
	 * 生命周期函数--监听页面加载
	 */ onLoad() {
		var that = this;
		this.getShareImage();
	},
	onShow() {
		var that = this;
	},

	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady: function() {},
	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide: function() {},
	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload: function() {},
	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh: function() {},
	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom: function() {},
	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage: function() {
		return {
			title: uni.getStorageSync('setting').desc,
			path: '/pages/index/index?user=' + this.user,
			imageUrl: '',
			success: function(res) {
				console.log('success22:' + JSON.stringify(res));
			},
			fail: function(err) {
				console.log('fail22:' + JSON.stringify(err));
			}
		};
	},
	methods: {
		longpress() {
			console.log(222);
			this.savePhoto();
		},
		jumpzuo() {
			uni.navigateBack();
		},
		savePhoto() {
			uni.downloadFile({
				//下载文件资源到本地,返回文件的本地临时路径
				url: this.shareImage, //网络图片路径
				// url: this.urlimg + this.shareImage, //网络图片路径
				success: res => {
					var imageUrl = res.tempFilePath; //临时文件路径
					uni.saveImageToPhotosAlbum({
						//保存图片到系统相册
						filePath: imageUrl,
						success: res => {
							console.log('图片保存成功');
							uni.showToast({
								title: '图片已保存至相册'
							});
						},
						fail: err => {
							console.log('图片保存失败');
						}
					});
				},fail: res =>{
					uni.showToast({
						title: res
					});
				}
			});
		},
		getShareImage: function() {
			var that = this;
			uni.showLoading({
				title: '正在生成海报'
			});
			var data = {
				token: uni.getStorageSync('token')
			};
			// request.get(`index.php?s=/api/user/share&wxapp_id=` + uni.getStorageSync('web_id'), data).then(res => {
				request.get(`index.php?s=/api/user.dealer.qrcode/poster&wxapp_id=` + uni.getStorageSync('web_id'), data).then(res => {
				if (res.data.code == 1) {
					// that.code= res.data.data.shareData.code
					// that.user= res.data.data.shareData.user_id
					// that.shareImage= res.data.data.src
					// that.code= res.data.data.shareData.code
					// that.user= res.data.data.shareData.user_id
					that.shareImage= res.data.data.qrcode
				}
			});
		}
	}
};
</script>
<style>
@import './my_fenxiaoewm.css';
</style>
